package com.decoration.basic.controller.api;

import com.decoration.basic.entity.DecPhaseInf;
import com.decoration.basic.entity.JsonResult;
import com.decoration.basic.findCondition.DecFlowFindCondition;
import com.decoration.basic.findCondition.DecPhaseFindCondition;
import com.decoration.basic.service.DecFlowService;
import com.decoration.basic.service.DecUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class DecRelFlowController {

    private static Logger log = LoggerFactory.getLogger(DecRelFlowController.class);
    @Resource
    private DecFlowService decFlowService;

    @Resource
    private DecUserService decUserService;

    //项目阶段申请审批页面
    @RequestMapping(value = "/relflow/phaselist", method = RequestMethod.POST)
    @ResponseBody
    public JsonResult getRelFlowPhaselist(JsonResult jsonResult, @RequestBody DecPhaseFindCondition findCondition) {
        log.info("审批页面");

        List<DecPhaseInf> list = new ArrayList<>();
        try {
            list = decFlowService.getRelFlowPhaselist(findCondition);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setCode(JsonResult.FAILED_CODE);
            jsonResult.setMsg("获取审批界面异常");
            return jsonResult;
        }

        jsonResult.setCode(JsonResult.SUCCESS_CODE);
        jsonResult.setCount(list == null ? 0 : list.size());
        jsonResult.setMsg("获取审批界面成功");
        jsonResult.setData(list);
        return jsonResult;
    }

    //申请阶段审批
    @RequestMapping(value = "/relflow/check", method = RequestMethod.POST)
    @ResponseBody
    public JsonResult applyRelFlow(JsonResult jsonResult, @RequestBody DecPhaseInf findCondition) {
        log.info("流程申请");

        try {
            jsonResult = decFlowService.applyRelFolw(findCondition);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setCode(JsonResult.FAILED_CODE);
            jsonResult.setMsg("申请流程进度异常");
            return jsonResult;
        }

        return jsonResult;
    }

}
